import React, { Component } from 'react'

class App extends Component {
  state = {
    val: '123',
  }
  // 输入框输入执行的回调
  handlerChange = (e) => {
    console.log(e)
    this.setState({
      val: e.target.value,
    })
  }
  pub = () => {
    console.log('输入框的值', this.state.val)
  }
  render() {
    return (
      <div>
        <h1>受控组件(双向绑定)</h1>
        <input
          type="text"
          value={this.state.val}
          onChange={this.handlerChange}
        />
        <button onClick={this.pub}>提交</button>
      </div>
    )
  }
}
export default App
